package com.zz.yt.test.gloading;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.PhoneUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.whf.android.jar.base.latte.BaseActivity;
import com.whf.android.jar.util.log.LatteLogger;
import com.zz.yt.test.R;

import java.util.List;

public class SerialActivity extends BaseActivity {


    @Override
    protected Object setLayout() {
        return R.layout.activity_serial;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState) {

    }


    public void onClick1(View view) {
        //获取IMEI时需要动态的
        PermissionUtils
                .permission(PermissionConstants.PHONE)
                .theme(ScreenUtils::setFullScreen)
                .rationale((activity, shouldRequest) -> shouldRequest.again(true))
                .callback(new PermissionUtils.FullCallback() {
                    @Override
                    public void onGranted(@NonNull List<String> permissionsGranted) {
                        ok();
                    }

                    @Override
                    public void onDenied(@NonNull List<String> permissionsDeniedForever, @NonNull List<String> permissionsDenied) {
                        LatteLogger.d("权限永久拒绝", permissionsDeniedForever);
                        LatteLogger.d("权限拒绝", permissionsDenied);
                    }
                })
                .request();
    }

    @SuppressLint("MissingPermission")
    private void ok() {
        String string = getDeviceId();
        setTextView(R.id.id_text_name, string);
        LatteLogger.i("mobileMe：" + string);
    }

    @SuppressLint({"MissingPermission", "HardwareIds"})
    protected final String getDeviceId() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            return Settings.Secure.getString(this.getApplicationContext().getContentResolver(),
                    Settings.Secure.ANDROID_ID);
        }
        return PhoneUtils.getDeviceId();
    }
}
